//
//  BaseViewController.swift
//  swiftTest
//
//  Created by LiTing on 17/6/12.
//  Copyright © 2017年 LiTing. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    //MARK:- 懒加载属性
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    //MARK:- 定义变量
    var isLogin : Bool = false
    
    //MARK- 系统回调函数
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupNavigationItems()
    }
}

//MARK:- 设置UI界面
extension BaseViewController {
    //设置访客视图
    private func setupVisitorView() {
        view = visitorView
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), forControlEvents: .TouchUpInside)
    }
    
    ///设置导航栏左右的item
    private func setupNavigationItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseViewController.loginBtnClick))

    }
}

//MARK:- 事件监听
extension BaseViewController {
    @objc private func registerBtnClick() {
        print("registerBtnClick")
    }
    @objc private func loginBtnClick() {

        //1.创建授权控制器
        let oautVc = QAuthViewController()
        
        //2.包装导航栏控制器
        let oauthNav = UINavigationController(rootViewController:oautVc)
        
        //3.弹出控制器
        presentViewController(oauthNav, animated: true, completion: nil)
    }
}